package com.wwj.core.tasks;

import com.wwj.core.wawa.service.IWaWaMachineStatisticsService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;

@Component("statisticsTask")
public class StatisticsTask {

    @Resource
    private IWaWaMachineStatisticsService waWaMachineStatisticsService;

    /**
     * 每天凌晨00:05:00执行一次
     */
    @Scheduled(cron = "0 5 0 * * ?")
    public void execute() {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Calendar now = Calendar.getInstance();
            now.add(Calendar.DATE, -1);
            waWaMachineStatisticsService.updateWaWaMachineStatistics(sdf.format(now.getTime()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
